import request from '@utils/request'
import { APIParams, APIResult } from '@utils/request/type'
import { ConfigurationDTO, SelfConfigSaveForm } from '@/api/entity/self-config'
import { ServerEnum } from '@/api/enum/server'

/**
 * 分页查询
 * @param params
 */
export const getSelfConfigListByPageAPI = (params: APIParams.Page<any>) => request.post<APIResult.Page<ConfigurationDTO[]>>(ServerEnum.System + '/configuration/page', params)

/**
 *  条件查询
 * @param params
 */
export const getSelfConfigListAPI = (params: {
  // 创建时间
  createdAt?: string
  // 创建人
  createdBy?: number
  // 场景id
  groupId?: number
  // 场景名称
  groupName?: string
  // 主组态d
  id?: number
  // 组态名称
  name?: string
  // 组态属性值
  value?: string
}) => request.post<APIResult<ConfigurationDTO[]>>(ServerEnum.System + '/configuration/list', params)

/**
 * 根据id获取组态
 * @param params
 */
export const getSelfConfigByIdAPI = (params: {
  id: string
}) => request.get<APIResult<ConfigurationDTO>>(ServerEnum.System + '/configuration/getById/' + params.id)

/**
 * 根据场景id获取组态
 * @param params
 */
export const getSelfBySceneIdAPI = (params: { id: string }) => request.get<APIResult<ConfigurationDTO>>(ServerEnum.System + '/configuration/getByGroupId/' + params.id)

/**
 * 添加组态
 * @param params
 */
export const addSelfConfigAPI = (params: SelfConfigSaveForm) => request.post(ServerEnum.System + '/configuration/save', params)

/**
 * 编辑组态
 * @param params
 */
export const editSelfConfigAPI = (params: SelfConfigSaveForm) => request.post(ServerEnum.System + '/configuration/update', params)

/**
 * 删除组态
 * @param params
 */
export const delSelfConfigAPI = (params: { id: string }) => request.get(ServerEnum.System + '/configuration/deleteById/' + params.id)
